//
//  RGMessageContactCell.m
//  RedGrass
//
//  Created by wuyine on 2018/12/7.
//  Copyright © 2018年 hongcaosp. All rights reserved.
//

#import "RGMessageContactCell.h"

@interface RGMessageContactCell()
@property (nonatomic,strong) UIButton *messageBtn;
@end

@implementation RGMessageContactCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.contentView.backgroundColor = [UIColor blackColor];
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
        [self initChildUI];
        [self addChildMasonry];
    }
    return self;
}

- (void)setModel:(RGMessageContactModel *)model {
    self.userName.text = model.nickname;
    self.contentLabel.text = model.userComment;
    if (model.userComment.length > 0) {
        [self.userName mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.userIcon.mas_trailing).offset(10);
            make.top.equalTo(self.userIcon.mas_top).offset(2);
        }];
        
        [self.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.userName.mas_leading).offset(0);
            make.bottom.equalTo(self.userIcon.mas_bottom).offset(-2);
        }];
    }else {
        [self.userName mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.userIcon.mas_trailing).offset(10);
            make.centerY.equalTo(self.userIcon.mas_centerY).offset(0);
        }];
    }
    [self.userIcon setImageWithURL:[NSURL URLWithString:model.image] placeholder:IMAGE_NAMED(@"头像1")];
}

-(void) initChildUI{
    self.userName.font = FONT(customFontName,15);
//    self.userName.text = @"用户名";
    self.contentLabel.textColor = UICOLOR_WITH_RGBINT(0xbbbbbb);
    self.contentLabel.font = FONT(customFontName, 13);
//    self.contentLabel.text = @"签名内容";
    
    [self.dateLabel removeFromSuperview];
    [self addSubview:self.messageBtn];
}

-(void) addChildMasonry {
    
    [self.userIcon mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(50, 50));
        make.leading.mas_equalTo(15);
        make.centerY.mas_equalTo(0);
    }];
    
    [self.userName mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.userIcon.mas_trailing).offset(10);
        make.top.equalTo(self.userIcon.mas_top).offset(2);
    }];
    
    [self.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.userName.mas_leading).offset(0);
        make.bottom.equalTo(self.userIcon.mas_bottom).offset(-2);
    }];
    
    [_messageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(46, 46));
        make.centerY.mas_equalTo(0);
        make.trailing.mas_equalTo(-20);
    }];
}

#pragma mark - response
-(void)messageBtnClick:(UIButton *)button{
    if(self.messageBtnClickBlock){
        self.messageBtnClickBlock();
    }
}

- (UIButton *)messageBtn {
    if (!_messageBtn) {
        _messageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_messageBtn setImage:IMAGE_NAMED(@"发送消息") forState:UIControlStateNormal];
        [_messageBtn addTarget:self action:@selector(messageBtnClick:)
              forControlEvents:UIControlEventTouchUpInside];
    }
    return _messageBtn;
}


@end
